package com.leetcode.partition3;

/**
 * @author `RKC`
 * @date 2021/11/6 22:32
 */
public class LC201数字范围按位与 {

    public static int rangeBitwiseAnd(int left, int right) {
        //0和谁与都是0,
        //5: 0 1 0 1
        //6: 0 1 1 0
        //7: 0 1 1 1
        int i = 0;
        while (left != right) {
            left >>= 1;
            right >>= 1;
            i++;
        }
        return left << i;
    }

    public static void main(String[] args) {
        System.out.println(rangeBitwiseAnd(1, 2147483647));
    }
}
